/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.prolificinteractive.materialcalendarview.sample;

import ohos.aafwk.content.Intent;
import ohos.agp.components.element.VectorElement;
import ohos.agp.text.Font;

import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.CalendarMode;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import com.prolificinteractive.materialcalendarview.format.ArrayWeekDayFormatter;
import com.prolificinteractive.materialcalendarview.format.MonthArrayTitleFormatter;
import com.prolificinteractive.materialcalendarview.sample.tools.FontCache;

import org.threeten.bp.DayOfWeek;

/**
 * @since 2021-07-12
 */
public class CustomizeXmlAbility extends BaseAbility {
    MaterialCalendarView widget;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
       toolbarTitle.setText("XML Customization Example");
        widget = (MaterialCalendarView) findComponentById(ResourceTable.Id_calendarView);
        widget.setSelectionColor(COLOR_ACCENT);
        widget.setShowOtherDates(7);
        VectorElement vectorElementleft = new VectorElement(getContext(), ResourceTable.Graphic_ic_arrow_back);
        VectorElement vectorElementright = new VectorElement(getContext(), ResourceTable.Graphic_ic_arrow_forward);
        widget.setLeftArrow(vectorElementleft);
        widget.setRightArrow(vectorElementright);
        widget.setSelectionColor(COLOR_ACCENT);
        Font mFont=FontCache.get(this, "shrikhand_regular.ttf");
//        设置星期字体 非中文
        widget.setWeekDayTextAppearance(mFont);
//        设置年月字体 非中文
        widget.setHeaderTextAppearance(mFont);
//        设置字体捆绑
        widget.setDateTextAppearance(mFont);
        widget.addDecorators(new EnableOneToTenDecorator());

        CharSequence[] monthLabels ={"JAN","Feb","MARCH","April","MAY","June","JULY","Aug","SEPT","Oct","Nov","DEC"};
        widget.setTitleFormatter(new MonthArrayTitleFormatter(monthLabels));
        CharSequence[] weekDayLabels={"M","Tu","W","Th","F","Sa","Su"};
        widget.setWeekDayFormatter(new ArrayWeekDayFormatter(weekDayLabels));
        widget.setTileSize(84);
        widget.setTitleAnimationOrientation(MaterialCalendarView.VERTICAL);

        widget.state().edit()
            .setFirstDayOfWeek(DayOfWeek.THURSDAY)
            .setCalendarDisplayMode(CalendarMode.WEEKS)
            .commit();
    }

    @Override
    int contentLayoutRes() {
        return ResourceTable.Layout_ability_customization;
    }

    private static class EnableOneToTenDecorator implements DayViewDecorator {

        @Override
        public boolean shouldDecorate(CalendarDay day) {
            return day.getDay() <= 31;
        }

        @Override
        public void decorate(DayViewFacade view) {
            view.setDaysDisabled(false);
        }
    }
}

